package com.wangjiyuan.giftshuo.ui.activity.classify.strategy_details.column_details.all_details.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.classifybean.strategy.ColumnBean;
import com.wangjiyuan.giftshuo.config.classify.ConstantLength;
import com.wangjiyuan.giftshuo.ui.activity.other.more.MoreActivity;
import com.wangjiyuan.giftshuo.utils.RecyclerViewAdapterHelper;
import com.wangjiyuan.giftshuo.widget.coustomview.RectangleBac;

import java.util.List;

/**
 * Created by QXL on 2016/11/21.
 */

public class ColumnDetRecyclerAdapter extends RecyclerViewAdapterHelper<ColumnBean.DataBean.ColumnsBean> {
    public ColumnDetRecyclerAdapter(Context context, List<ColumnBean.DataBean.ColumnsBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_column_details, parent, false);
        return new ViewHolderColumnDet(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position) {
        ColumnBean.DataBean.ColumnsBean columnsBean = mList.get(position);
        int widthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
        int heightPixels = mContext.getResources().getDisplayMetrics().heightPixels;
        ((ViewHolderColumnDet)holder).textView_item_title.setText(columnsBean.getTitle());
        ((ViewHolderColumnDet) holder).textView_item_title.setHeight(heightPixels/16);

        ((ViewHolderColumnDet) holder).textView_item_author.setText(columnsBean.getAuthor());
        ((ViewHolderColumnDet) holder).textView_item_author.setHeight(heightPixels/16);

        RelativeLayout.LayoutParams imgLayoutParams=new RelativeLayout.LayoutParams(widthPixels/3,heightPixels/8);
        ((ViewHolderColumnDet) holder).imageView_item.setLayoutParams(imgLayoutParams);
        imgLayoutParams.setMargins(ConstantLength.IMG_COLUMN_DETAILS_WIDTH,ConstantLength.IMG_COLUMN_DETAILS_HEIGHT,
                ConstantLength.IMG_COLUMN_DETAILS_WIDTH,ConstantLength.IMG_COLUMN_DETAILS_HEIGHT);
        Glide.with(mContext).load(columnsBean.getCoverImageUrl())
                .centerCrop()
                .into(((ViewHolderColumnDet) holder).imageView_item);

    }

    class ViewHolderColumnDet extends RecyclerView.ViewHolder implements View.OnClickListener{
        RelativeLayout relativeLayout_item_columnDet;
        ImageView imageView_item;
        TextView textView_item_title,textView_item_author;
        RectangleBac rectangleBac_item_column;

        public ViewHolderColumnDet(View itemView) {
            super(itemView);
            imageView_item= (ImageView) itemView.findViewById(R.id.image_item_column_details);
            textView_item_title= (TextView) itemView.findViewById(R.id.textView_item_column_details_title);
            textView_item_author= (TextView) itemView.findViewById(R.id.textView_item_column_details_author);
            rectangleBac_item_column= (RectangleBac) itemView.findViewById(R.id.rectangleBac_item_column);
            rectangleBac_item_column.setPadding(ConstantLength.IMG_COLUMN_DETAILS_WIDTH*2,ConstantLength.IMG_COLUMN_DETAILS_HEIGHT,
                    ConstantLength.IMG_COLUMN_DETAILS_WIDTH*2,ConstantLength.IMG_COLUMN_DETAILS_HEIGHT);

            relativeLayout_item_columnDet= (RelativeLayout) itemView.findViewById(R.id.relativeLayout_item_columnDet);
            relativeLayout_item_columnDet.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.relativeLayout_item_columnDet:
                    int itemID = mList.get(getAdapterPosition()).getId();
                    Intent intent = new Intent(mContext, MoreActivity.class);
                    intent.putExtra("id", itemID);
                    mContext.startActivity(intent);
                    break;
            }
        }
    }
}
